<?php
// +----------------------------------------------------------------------
// | Description: 部门控制器
// +----------------------------------------------------------------------
// | Author: linchuangbin <linchuangbin@honraytech.com>
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\service\PostService;
use app\admin\validate\PostValidate;
use common\controller\AdminAuthController;
use think\response\Json;

/**
 * Class Post
 * @package app\admin\controller
 * @property PostService $service
 * @property PostValidate $validate
 */
class Post extends AdminAuthController
{

    /**
     * @return bool|void
     */
    public function initialize()
    {
        parent::initialize();
        $this->service = PostService::instance();
        $this->validate = PostValidate::instance();
        return true;
    }

    /**
     * @return Json
     */
    public function index()
    {
        $param = $this->param;
        $PostService = PostService::instance();
        $this->validate->runCheck($param, '', __FUNCTION__);
        $list = $PostService->getList($param);
        $count = $PostService->getCount($param);
        return $this->json_responce( compact(['list', 'count']));
    }

    /**
     * @param $id
     * @return Json
     */
    public function read()
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->getByID($param);
        return $this->json_responce($data);
    }

    /**
     * @return Json
     */
    public function save()
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->createData($param);
        return $this->json_responce();
    }

    /**
     * @return Json
     */
    public function update()
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->updateByID($param);
        return $this->json_responce();
    }

    /**
     * @return Json
     */
    public function delete()
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->delByID($param);
        return $this->json_responce();
    }

    /**
     * @return Json
     */
    public function deletes()
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->delByIDs($param);
        return $this->json_responce();
    }

    /**
     * @return Json
     */
    public function enables()
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->enableByIDs($param);
        return $this->json_responce();
    }
}
 